package com.oma.testcase;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class DoctorCode {
	
	public void code(WebDriver driver, String code){
		
		WebElement dc = driver.findElement(By.xpath("//input[@id='docCode']"));
		dc.sendKeys(code);
		driver.findElement(By.xpath("//button[@id='addDoctorBtn']")).click();
		driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
		
		
		if(driver.findElement(By.xpath
				("//p[@id='errorMessage' and contains(., 'Doctor Code already exists. Please assign a new Doctor Code.')]"))
				.isDisplayed()){
				
			driver.findElement(By.xpath("//div[@id='myModal2']/div[3]/button")).click();
			dc.clear();
			System.out.println("Doctor Code exists: " +code);
			int docCode = Integer.parseInt(code);
			docCode++;
			String dCode = Integer.toString(docCode);
			code(driver , dCode);
			
		}
		else	
		{
			driver.findElement(By.xpath("//div[@id='modalError3']/div[3]/button[1]")).click();
			driver.findElement(By.xpath("//div[@id='modalError']/div[3]/button[1]")).click();
			driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
			System.out.println("Successful assigned doctor code: " +code);
		}
	}
}
